Class Continuation<T>

java.lang.Object
edu.uky.ai.lp.ai.Continuation<T>
Type Parameters:
T - the type of value that this continuation will return
Direct Known Subclasses:
Prover

public abstract class Continuation<T>
extends java.lang.Object

A continuation, sometimes called a generator, is like a function which can return multiple values in sequence. Each time the continuation returns a value, it pauses execution and waits to be called again. Subsequent calls will pick up where the last one left off.

A continuation has 4 important types of events in its lifecycle:

  • CALL: The first time the continuation is invoked.
  • REDO: Subsequent invocations.
  • EXIT: Each time the continuation returns a value.
  • FAIL: The final event, indicating there are no more values to be returned.

Continuations are implemented by extending this class and overriding the run() method. Each time the continuation should return a value, run() should call yield(Object). When run() finishes, the continuation will FAIL.

Author:
Stephen G. Ware
  • Constructor Summary

    Constructors 
    Constructor Description
    Continuation()  
  • Method Summary

    Modifier and Type Method Description
    T call()
    Invokes the continuation, picking up where the previous invocation (if any) stopped.
    boolean done()
    Indicates whether or not more CALLs can be made to this continuation.
    protected abstract void run()
    The actual work to be done by the continuation.
    protected void yield​(T value)
    This method is called each time the continuation should return a value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • done

      public boolean done()
      Indicates whether or not more CALLs can be made to this continuation.
      Returns:
      true if no more calls can be mode, false otherwise
    • call

      public T call()
      Invokes the continuation, picking up where the previous invocation (if any) stopped.
      Returns:
      the next value returned by the continuation, or null if this call resulted in FAIL
    • run

      protected abstract void run()
      The actual work to be done by the continuation.
    • yield

      protected final void yield​(T value)
      This method is called each time the continuation should return a value. The value to be returned is passed as a parameter. When this method is called, the continuation will pause until the next REDO event.
      Parameters:
      value - the value to be returned